function initPage() {
	window.onresize = onResize;
	sessionStorage.setItem("indexType", 'old'); 
	//checkLogin();
	isLogin();
	$('#login_btn').click(function(){
		/*if($('#login').text() == "退出"){
			window.location.href = "pages/main.html";
		}else{
			window.location.href = "pages/login.html";
		}*/
		$.ajax({
			url: 'pv/login/loginInfo',
			type: "get",
			success:function(res){
				result = res;
				if (result != "") {
					window.location.href = "pages/main.html";
				}else {
					window.location.href = "pages/login.html";
				}
			}
		})
	});

	$.ajax({
		url: "g/service/Sample/getUserId",
		type:'POST',
		cache:false,
		async:false,
		dataType: "json",
		contentType:"application/json",
        success:function(data){
        	if(data == 0 || data == 1) {
        		$("#system").css("display","block");
        	} else {
        		$("#system").hide();
        	}
        }
	});

	/*$('#login').click(function(){
		if($('#login').text() == "退出"){
			$.ajax({
				dataType: "json",
				url: "pv/login/logout"
			}).done(function(res) {
			});
			$('#login').text("登录");
		}else{
			window.location.href = "pages/login.html";
		}
	});
	*/
	initSystem();
	onResize();
	var sys = sessionStorage.getItem("sys");
	if(sys=='1'){
		$('#teamlink').attr("iframe-src","JSteam.html");
	}
}
//判断是否为登陆状态
function isLogin() {
	$.ajax({
		url: 'pv/login/loginInfo',
		type: "get",
		success:function(res){
			result = res;
			if (result != "") {
				$("#login").text(result);
				$("#jump").attr("href","javascript:void(0);");
			}else {
				$("#login").text("登录/注册");
				$("#jump").attr("iframe-src","pages/login.html");
				$("#loginUser").remove();
			}
		}
	})
}

/*function checkLogin() {
	$.ajax({
		dataType: "json",
		url: "pv/login/checkLogin"
	}).done(function(res) {
		if(res.result){
			$('#login').text("退出");
		}else{
			$('#login').text("登录");
		}
	});
}*/

function onResize() {
	console.log("onResize");
	var viewWidth = $("#viewPanel").width();
	var scale = viewWidth / 1920;
	var topHeight = parseInt(800 * scale);
	var contentHeight = parseInt(600 * scale);
	var navbarHeight = parseInt(450 * scale);
	var footerHeight = parseInt(100 * scale);

	$("#content0").height(topHeight);
	$("#login_dialog").height(topHeight-60);
	$("#content1").height(contentHeight);
	$("#content2").height(contentHeight);
	$("#content3").height(contentHeight);
	$("#content4").height(contentHeight);
	$("#content5").height(contentHeight);
	$("#navbar").height(navbarHeight);
	$("#footer").height(footerHeight);
};
function initSystem(){
	var sys = sessionStorage.getItem("sys");
	invoke_sys('getSystem', {sys:sys}, function(data){
		$("#logo_icon").attr('src',' images/'+data.data[0].logo_pic);
		$("#logo_title").text(data.data[0].logo_text);
		$('#login_exit').click(function(){
			$.ajax({
	            url: 'pv/login/logout',
	            dataType: 'text'
	        }).done(function(res) {
	    	});
			window.location.href=data.data[0].sys_index;
		});
    });
};
function invoke_sys(url, args, callback){
	var r, op = {
			url: 'g/service/Sysconfig/' + url,
			type:'POST',
			cache:false,
			async:true,
			dataType:'json',
			data:args ? JSON.stringify(args) : null,
			contentType:"application/json"
		};
	if(typeof callback == 'function'){
		op.success = function(data){
			if(data.error)return alert(data.error);
			callback(data);
		}
	} else {
		op.async = false;
		op.success = function(data){
			r = data
		};
	}
	$.ajax(op);
	if(r)if(r.error){
		alert(r.error);
		return null;
	}
	return r;
};
